package com.zf.yichat.api.controller.app;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zf.yichat.api.controller.BaseController;
import com.zf.yichat.model.SysDict;
import com.zf.yichat.service.SysDictService;
import com.zf.yichat.utils.response.FsResponse;
import com.zf.yichat.utils.response.FsResponseGen;
import com.zf.yichat.vo.DictKey;
import org.apache.http.util.TextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
@RequestMapping("app")
public class AppController extends BaseController {

    @Autowired
    private SysDictService sysDictService;
    @PostMapping("/serverlist")
    public FsResponse version() {
         String sysDicServerList=   Optional.ofNullable(sysDictService.selectOne(DictKey.sys_dict_server_list)).map(SysDict::getMemo).orElse("");
        JSONArray jsonArray=new JSONArray();
        if(!TextUtils.isEmpty(sysDicServerList)){
           String[]  listData=sysDicServerList.split("#");
           for(String serverName:listData){
                jsonArray.add(serverName.trim());
           }
        }

        return FsResponseGen.successData(jsonArray);
    }



}
